package com.example.cola.domain.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.regex.Pattern;

/**
 * 手机号值对象
 * 
 * @author 资深开发专家
 * @version 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PhoneNumber {
    
    private String value;
    
    // 中国手机号正则表达式
    private static final Pattern PHONE_PATTERN = Pattern.compile(
        "^1[3-9]\\d{9}$"
    );
    
    public static PhoneNumber of(String phoneNumber) {
        if (phoneNumber == null || phoneNumber.trim().isEmpty()) {
            throw new IllegalArgumentException("手机号不能为空");
        }
        
        String trimmedPhone = phoneNumber.trim();
        if (!PHONE_PATTERN.matcher(trimmedPhone).matches()) {
            throw new IllegalArgumentException("手机号格式不正确");
        }
        
        return new PhoneNumber(trimmedPhone);
    }
    
    @Override
    public String toString() {
        return value;
    }
}
